package com.ljm.boot.rabbitmq.producer;


import com.ljm.boot.rabbitmq.constant.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 消息发送者
 */
@Service
public class FanoutProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    //fanout广播模式发送消息
    public void sendFanout(Object msg){
        System.out.println("发送消息-" + msg);
        //因为是fanout广播模式，不需要指定路由，这里路由赋空值处理
        rabbitTemplate.convertAndSend(RabbitMQConstant.FANOUT_EXCHANGE,"",msg);
    }

}
